﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XDeal.DAL.Entities;
namespace XDeal.DAL.Implements
{
    public class ApplyAreaDAO:BaseDAO
    {
        public ApplyAreaDAO()
            : base()
        { }



        #region GET BASIC
        /// <summary>
        /// Get All ApplyArea
        /// </summary>
        /// <returns>List of ApplyAreas</returns>
        public List<ApplyArea> GetAll()
        {
            return XDealDataContext.ApplyAreas.ToList<ApplyArea>();
        }

        /// <summary>
        /// Get ApplyArea by ID
        /// </summary>
        /// <param name="ID">ApplyArea ID</param>
        /// <returns>One ApplyArea</returns>
        public ApplyArea GetByID(int ID)
        {
            return XDealDataContext.ApplyAreas.Where(ob => ob.ID_i == ID).FirstOrDefault<ApplyArea>();
        }
        #endregion

        #region GET ADVANCE

        #endregion

        #region INSERT, UPDATE, DELETE
        /// <summary>
        /// Insert ApplyArea
        /// </summary>
        /// <param name="ob">ApplyArea Object</param>
        /// <returns>True: Successful | False: Fail</returns>
        public bool Insert(ApplyArea ob)
        {
            try
            {
                XDealDataContext.AddToApplyAreas(ob);
                XDealDataContext.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// Update ApplyArea by Object
        /// </summary>
        /// <param name="ob">ApplyArea Object</param>
        /// <returns>True: Successful | False: Fail</returns>
        public bool Update(ApplyArea ob)
        {
            try
            {
                ApplyArea _ob = GetByID(ob.ID_i);
                if (_ob != null)
                {
                    XDealDataContext.ApplyCurrentValues(_ob.EntityKey.EntitySetName, ob);
                    XDealDataContext.SaveChanges();
                    return true;
                }
                else
                    return false;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// Delete ApplyArea by Object
        /// </summary>
        /// <param name="ob">ApplyArea Object</param>
        /// <returns>True: Successful | False: Fail</returns>
        public bool Delete(ApplyArea ob)
        {
            try
            {
                ApplyArea _ob = GetByID(ob.ID_i);
                if (_ob != null)
                {
                    XDealDataContext.DeleteObject(_ob);
                    XDealDataContext.SaveChanges();
                    return true;
                }
                else
                    return false;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// Delete By ID
        /// </summary>
        /// <param name="ID">ApplyArea ID</param>
        /// <returns>True: Successful | False: Fail</returns>
        public bool Delete(int ID)
        {
            try
            {
                ApplyArea _ob = GetByID(ID);
                if (_ob != null)
                {
                    XDealDataContext.DeleteObject(_ob);
                    XDealDataContext.SaveChanges();
                    return true;
                }
                else
                    return false;
            }
            catch
            {
                return false;
            }
        }
        #endregion
    }
}
